//package moni.anyou.com.view.view;
//
//import android.Manifest;
//import android.content.Intent;
//import android.content.pm.PackageManager;
//import android.graphics.PorterDuff;
//import android.os.Bundle;
//import android.util.Log;
//import android.view.View;
//import android.widget.ImageView;
//import android.widget.Toast;
//
//import androidx.annotation.NonNull;
//import androidx.appcompat.app.AppCompatActivity;
//import androidx.core.app.ActivityCompat;
//import androidx.core.content.ContextCompat;
//
//import com.google.gson.Gson;
//import com.tencent.imsdk.TIMConversationType;
//import com.tencent.qcloud.presentation.presenter.ChatPresenter;
//import com.tencent.qcloud.timchat.model.Message;
//import com.tencent.qcloud.timchat.model.TextMessage;
//import com.tencent.qcloud.ui.ChatInput;
//
//import org.greenrobot.eventbus.EventBus;
//import org.greenrobot.eventbus.Subscribe;
//import org.greenrobot.eventbus.ThreadMode;
//
//import java.util.Locale;
//
////import io.agora.rtc.IRtcEngineEventHandler;
////import io.agora.rtc.RtcEngine;
//import moni.anyou.com.view.R;
//
//public class VoiceChatViewActivity extends AppCompatActivity {
//
////    private static final String LOG_TAG = VoiceChatViewActivity.class.getSimpleName();
////
////    private static final int PERMISSION_REQ_ID_RECORD_AUDIO = 22;
////
////
////    private String info;
//////    private ChatInput.ChatInfoBean chatInfiBean;
////
////
////    private RtcEngine mRtcEngine;// Tutorial Step 1
////    private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { // Tutorial Step 1
////
////        @Override
////        public void onUserOffline(final int uid, final int reason) { // Tutorial Step 4
////            runOnUiThread(new Runnable() {
////                @Override
////                public void run() {
////                    onRemoteUserLeft(uid, reason);
////                }
////            });
////        }
////
////        @Override
////        public void onUserMuteAudio(final int uid, final boolean muted) { // Tutorial Step 6
////            runOnUiThread(new Runnable() {
////                @Override
////                public void run() {
////                    onRemoteUserVoiceMuted(uid, muted);
////                }
////            });
////        }
////    };
////    private String roomId;
////
////
////    private boolean isSendFinishMsg=false;
////
////
////    //接收音视频消息
////    @Subscribe(threadMode = ThreadMode.MAIN)
////    public void onEventMainThread(ChatInput.ChatInfoBean bean) {
////       if(ChatInput.steamChatFinish.equals(bean.chatType)||ChatInput.streamChatClose.equals(bean.chatType))
////        {
////            isSendFinishMsg=true;
////            finish();
////        }
////    }
////
////    @Override
////    protected void onCreate(Bundle savedInstanceState) {
////        super.onCreate(savedInstanceState);
////        setContentView(R.layout.activity_voice_chat_view);
////
////        if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
////            initAgoraEngineAndJoinChannel();
////        }
////
////
////        info = getIntent().getStringExtra("chat");
////
////
////
////
//////        chatInfiBean = new Gson().fromJson(
//////                info.split("id=")[1],
//////                ChatInput.ChatInfoBean.class);
////
////
////
//////        Integer int_myIdentify = Integer.valueOf(chatInfiBean.sendId);
//////        Integer int_identify = Integer.valueOf(chatInfiBean.receiveId);
//////        if(int_identify<int_myIdentify)
//////        {
//////            roomId=int_identify+"_"+int_myIdentify;
//////        }else
//////        {
//////            roomId=int_myIdentify+"_"+int_identify;
//////        }
////
////
////        roomId="test";
////
////        EventBus.getDefault().register(this);
////
////    }
////
////    private void initAgoraEngineAndJoinChannel() {
////        initializeAgoraEngine();     // Tutorial Step 1
////        joinChannel();               // Tutorial Step 2
////    }
////
////    public boolean checkSelfPermission(String permission, int requestCode) {
////        Log.i(LOG_TAG, "checkSelfPermission " + permission + " " + requestCode);
////        if (ContextCompat.checkSelfPermission(this,
////                permission)
////                != PackageManager.PERMISSION_GRANTED) {
////
////            ActivityCompat.requestPermissions(this,
////                    new String[]{permission},
////                    requestCode);
////            return false;
////        }
////        return true;
////    }
////
////    @Override
////    public void onRequestPermissionsResult(int requestCode,
////                                           @NonNull String permissions[], @NonNull int[] grantResults) {
////        Log.i(LOG_TAG, "onRequestPermissionsResult " + grantResults[0] + " " + requestCode);
////
////        switch (requestCode) {
////            case PERMISSION_REQ_ID_RECORD_AUDIO: {
////                if (grantResults.length > 0
////                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
////                    initAgoraEngineAndJoinChannel();
////                } else {
////                    showLongToast("No permission for " + Manifest.permission.RECORD_AUDIO);
////                    finish();
////                }
////                break;
////            }
////        }
////    }
////
////    public final void showLongToast(final String msg) {
////        this.runOnUiThread(new Runnable() {
////            @Override
////            public void run() {
////                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
////            }
////        });
////    }
////
////    @Override
////    protected void onDestroy() {
////        super.onDestroy();
////
////        leaveChannel();
////        RtcEngine.destroy();
////        mRtcEngine = null;
////
////
//////        if(!isSendFinishMsg) {
//////            ChatPresenter presenter = new ChatPresenter(chatInfiBean.sendId, TIMConversationType.C2C);
//////            presenter.start();
//////            chatInfiBean.streamType = ChatInput.steamChatFinish;
//////            String str = ChatInput.streamChatClose + new Gson().toJson(chatInfiBean);
//////            Message message = new TextMessage(str);
//////            presenter.sendMessage(message.getMessage());
//////
//////            presenter.stop();
//////
//////
//////        }
////        EventBus.getDefault().unregister(this);
////    }
////
////    // Tutorial Step 7
////    public void onLocalAudioMuteClicked(View view) {
////        ImageView iv = (ImageView) view;
////        if (iv.isSelected()) {
////            iv.setSelected(false);
////            iv.clearColorFilter();
////        } else {
////            iv.setSelected(true);
////            iv.setColorFilter(getResources().getColor(io.agora.tutorials1v1vcall.R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
////        }
////
////        mRtcEngine.muteLocalAudioStream(iv.isSelected());
////    }
////
////    // Tutorial Step 5
////    public void onSwitchSpeakerphoneClicked(View view) {
////        ImageView iv = (ImageView) view;
////        if (iv.isSelected()) {
////            iv.setSelected(false);
////            iv.clearColorFilter();
////        } else {
////            iv.setSelected(true);
////            iv.setColorFilter(getResources().getColor(io.agora.tutorials1v1vcall.R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
////        }
////
////        mRtcEngine.setEnableSpeakerphone(view.isSelected());
////    }
////
////    // Tutorial Step 3
////    public void onEncCallClicked(View view) {
////        finish();
////    }
////
////    // Tutorial Step 1
////    private void initializeAgoraEngine() {
////        try {
////            Log.d(LOG_TAG, "initializeAgoraEngine");
////            mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
////        } catch (Exception e) {
////            Log.e(LOG_TAG, Log.getStackTraceString(e));
////
////            throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
////        }
////    }
////
////    // Tutorial Step 2
////    private void joinChannel() {
////        Log.d(LOG_TAG, "joinChannel");
////        mRtcEngine.joinChannel(null, roomId, "Extra Optional Data", 0); // if you do not specify the uid, we will generate the uid for you
////    }
////
////    // Tutorial Step 3
////    private void leaveChannel() {
////
////        Log.d(LOG_TAG, "leaveChannel");
////        mRtcEngine.leaveChannel();
////    }
////
////    // Tutorial Step 4
////    private void onRemoteUserLeft(int uid, int reason) {
////
////        Log.d(LOG_TAG, "onRemoteUserLeft");
////        showLongToast(String.format(Locale.US, "user %d left %d", (uid & 0xFFFFFFFFL), reason));
////        View tipMsg = findViewById(R.id.quick_tips_when_use_agora_sdk); // optional UI
////        tipMsg.setVisibility(View.VISIBLE);
////    }
////
////    // Tutorial Step 6
////    private void onRemoteUserVoiceMuted(int uid, boolean muted) {
////        Log.d(LOG_TAG, "onRemoteUserVoiceMuted");
////        showLongToast(String.format(Locale.US, "user %d muted or unmuted %b", (uid & 0xFFFFFFFFL), muted));
////    }
//
//
//    private static final String LOG_TAG = VoiceChatViewActivity.class.getSimpleName();
//
//    private static final int PERMISSION_REQ_ID_RECORD_AUDIO = 22;
//
//    private RtcEngine mRtcEngine;// Tutorial Step 1
//    private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() { // Tutorial Step 1
//
//        @Override
//        public void onUserOffline(final int uid, final int reason) { // Tutorial Step 4
//            runOnUiThread(new Runnable() {
//                @Override
//                public void run() {
//                    onRemoteUserLeft(uid, reason);
//                }
//            });
//        }
//
//        @Override
//        public void onUserMuteAudio(final int uid, final boolean muted) { // Tutorial Step 6
//            runOnUiThread(new Runnable() {
//                @Override
//                public void run() {
//                    onRemoteUserVoiceMuted(uid, muted);
//                }
//            });
//        }
//    };
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_voice_chat_view);
//
//        if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
//            initAgoraEngineAndJoinChannel();
//        }
//    }
//
//    private void initAgoraEngineAndJoinChannel() {
//        initializeAgoraEngine();     // Tutorial Step 1
//        joinChannel();               // Tutorial Step 2
//    }
//
//    public boolean checkSelfPermission(String permission, int requestCode) {
//        Log.i(LOG_TAG, "checkSelfPermission " + permission + " " + requestCode);
//        if (ContextCompat.checkSelfPermission(this,
//                permission)
//                != PackageManager.PERMISSION_GRANTED) {
//
//            ActivityCompat.requestPermissions(this,
//                    new String[]{permission},
//                    requestCode);
//            return false;
//        }
//        return true;
//    }
//
//    @Override
//    public void onRequestPermissionsResult(int requestCode,
//                                           @NonNull String permissions[], @NonNull int[] grantResults) {
//        Log.i(LOG_TAG, "onRequestPermissionsResult " + grantResults[0] + " " + requestCode);
//
//        switch (requestCode) {
//            case PERMISSION_REQ_ID_RECORD_AUDIO: {
//                if (grantResults.length > 0
//                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//                    initAgoraEngineAndJoinChannel();
//                } else {
//                    showLongToast("No permission for " + Manifest.permission.RECORD_AUDIO);
//                    finish();
//                }
//                break;
//            }
//        }
//    }
//
//    public final void showLongToast(final String msg) {
//        this.runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
//            }
//        });
//    }
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//
//        leaveChannel();
//        RtcEngine.destroy();
//        mRtcEngine = null;
//    }
//
//    // Tutorial Step 7
//    public void onLocalAudioMuteClicked(View view) {
//        ImageView iv = (ImageView) view;
//        if (iv.isSelected()) {
//            iv.setSelected(false);
//            iv.clearColorFilter();
//        } else {
//            iv.setSelected(true);
//            iv.setColorFilter(getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
//        }
//
//        mRtcEngine.muteLocalAudioStream(iv.isSelected());
//    }
//
//    // Tutorial Step 5
//    public void onSwitchSpeakerphoneClicked(View view) {
//        ImageView iv = (ImageView) view;
//        if (iv.isSelected()) {
//            iv.setSelected(false);
//            iv.clearColorFilter();
//        } else {
//            iv.setSelected(true);
//            iv.setColorFilter(getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.MULTIPLY);
//        }
//
//        mRtcEngine.setEnableSpeakerphone(view.isSelected());
//    }
//
//    // Tutorial Step 3
//    public void onEncCallClicked(View view) {
//        finish();
//    }
//
//    // Tutorial Step 1
//    private void initializeAgoraEngine() {
//        try {
//            mRtcEngine = RtcEngine.create(getBaseContext(), "5b9a4c1dc16a44de8473c6d897842dba", mRtcEventHandler);
//           /**getString(R.string.agora_app_id)**/
//        } catch (Exception e) {
//            Log.e(LOG_TAG, Log.getStackTraceString(e));
//
//            throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
//        }
//    }
//
//    // Tutorial Step 2
//    private void joinChannel() {
//        mRtcEngine.joinChannel(null, "test", "Extra Optional Data", 0); // if you do not specify the uid, we will generate the uid for you
//    }
//
//    // Tutorial Step 3
//    private void leaveChannel() {
//        mRtcEngine.leaveChannel();
//    }
//
//    // Tutorial Step 4
//    private void onRemoteUserLeft(int uid, int reason) {
//        showLongToast(String.format(Locale.US, "user %d left %d", (uid & 0xFFFFFFFFL), reason));
//        View tipMsg = findViewById(R.id.quick_tips_when_use_agora_sdk); // optional UI
//        tipMsg.setVisibility(View.VISIBLE);
//    }
//
//    // Tutorial Step 6
//    private void onRemoteUserVoiceMuted(int uid, boolean muted) {
//        showLongToast(String.format(Locale.US, "user %d muted or unmuted %b", (uid & 0xFFFFFFFFL), muted));
//    }
//}
